home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / SETLINE < prev    next >
Encoding:
Text File  |  1985-12-29  |  3.5 KB  |  130 lines

  1. ;---------------SETLINE---routine begins--------------------------+
  2. ; ROUTINE SETLINE from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page 145
  4. ; FUNCTION: draws a line from (x1,y1) to (x2,y2) in the spec-
  5. ; ified color.  It uses BRESENHAM's algorithm.
  6. ;
  7. ; INPUT: Upon entry:
  8. ;     x1 contains x-coordinate of starting point
  9. ;     y1 contains y-coordinate of starting point
  10. ;     x2 contains x-coordinate of end point
  11. ;     y2 contains y-coordinate of end point
  12. ;     color contains the color of the line
  13. ;
  14. ; OUTPUT: Just to the screen
  15. ;
  16. ; REGISTERS USED:  No registers are modified
  17. ;
  18. ; SEGMENTS REFERENCED:  Upon entry ES must point to video RAM at
  19. ; B8000h and DS must point to a data segment used by the point-
  20. ; plotting routine (see SETPT or XORPT above)
  21. ;
  22. ; ROUTINES CALLED:  SETPT (can substitute XORPT)
  23. ;
  24. ; SPECIAL NOTES: No bounds checking is performed.  The user must make
  25. ; sure that the coordinates and the color are in their proper ranges.
  26. ; That is, x1 & x2 must be between 0 and 319; y1 & y2 must be between
  27. ; 0 and 199, and color must be between 0 and 3.
  28. ;
  29. ; ROUTINE TO DRAW A LINE
  30. ;
  31. setline    proc    far
  32.     push    bx        ; save registers
  33.     push     cx         ;
  34.     push     dx
  35.     push    si
  36.     push    di
  37.     push    ax
  38. ;
  39. ; set up x and y updates
  40.     mov    si,1        ;start with positive 1 for x update
  41.     mov    di,1        ;start with positive 1 for y update
  42. ;
  43. ; find |y2-y1|
  44.     mov    dx,y2        ;get y2
  45.     sub    dx,y1        ;subtract y2
  46.     jge    storey        ;skip if y2-y1 is non-negative
  47.     neg    di        ;move in negative y direction
  48.     neg    dx        ;absolute value of y2-y1
  49. storey:
  50.     mov    deldy,di        ;store y update for diagonal moves
  51. ;
  52. ; find |x1-x2|
  53.     mov    cx,x2        ;get x2
  54.     sub    cx,x1        ;subtract x2
  55.     jge    storex        ;skip if x2-x1 is non-negative
  56.     neg    si        ;move in negative x direction
  57.     neg    cx        ;absolute value of x2-x1
  58. storex:
  59.     mov    deldx,si    ;store x update for diagonal moves
  60. ;
  61. ; sort |y2-y1| and |x2-x1|
  62.     cmp    cx,dx        ; compare dels with delp
  63.     jge    setdiag        ; skip if straight moves in y direction
  64.     mov    si,0        ; if straight=vertical, kill & update
  65.     xchg    cx,dx        ;   & exchange differences
  66.     jmp    storedelsxy
  67. ;
  68. setdiag:
  69.     mov    di,0        ; if straight = horizontal, kill y update
  70. ;
  71. ; store dels, delp, delsx and delsy
  72. storedelsxy:
  73.     mov    dels,cx        ; change in straight direction
  74.     mov    delp,dx        ; change in perpendicular to straight
  75.     mov    delsx,si    ; x update in straight direction
  76.     mov    delsy,di    ; y update in straight direction
  77. ;
  78. ; get initial values for x and y
  79.     mov    si,x1        ; x coordinate
  80.     mov    di,y1        ; y coordinate
  81. ;
  82. ; compute initial value and increments for error function
  83.     mov    ax,delp
  84.     sal    ax,1        ; 2 * delp
  85.     mov    delse,ax    ; change if straight move
  86. ;
  87.     sub    ax,cx        ; 2*delp - dels
  88.     mov    bx,ax        ; initial value
  89. ;
  90.     sub    ax,cx        ; 2*delp - 2*dels
  91.     mov    delde,ax    ; change if diagonal move
  92. ;
  93. ; adjust count
  94.     inc    cx
  95. ;
  96. ; get the color
  97.     mov    dx,color    ; get the color
  98. ;
  99. ; main loop structure
  100. lineloop:
  101.     call     setpt        ; plot the point
  102.     cmp    bx,0        ; determine if straight or diagonal move
  103.     jge    diagonal
  104. ;
  105. ; case for straight move
  106. straight:
  107.     add    si,delsx    ; update x
  108.     add    di,delsy    ; update y
  109.     add    bx,delse    ; update error term
  110.     loop    lineloop    ; next point
  111.     jmp    lineexit
  112. ;
  113. ; case for diagonal move
  114. diagonal:
  115.     add    si,deldx    ; update x
  116.     add    di,deldy    ; update y
  117.     add    bx,delde    ; update error term
  118.     loop    lineloop    ; next point
  119. ;
  120. lineexit:
  121.     pop    ax        ; restore registers
  122.     pop    di
  123.     pop    si
  124.     pop    dx
  125.     pop    cx
  126.     pop    bx
  127.     ret            ; return
  128. setline    endp
  129. ;---------------SETLINE---routine ends---------------------------+
  130.